package com.itheima.app.exception;

import com.itheima.vo.ErrorResult;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import java.util.HashMap;
import java.util.Map;

@ControllerAdvice
public class GlobalExceptionAdvice {


    @ExceptionHandler(Exception.class)
    public ResponseEntity exceptionHandler(Exception ex) {

        ex.printStackTrace();
        return ResponseEntity.status(500).body(ErrorResult.error());
    }
    @ExceptionHandler(PublishException.class)
    public ResponseEntity businessExceptionHandler(Exception ex) {
        ex.printStackTrace();
        Map<String, String> errorResult = new HashMap<>();
        errorResult.put("message", ex.getMessage());
        return ResponseEntity.status(500).body(errorResult);
    }
}
